<!DOCTYPE html>
<html>
<head>
    <title>API连接测试</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        button { padding: 10px 20px; margin: 10px; font-size: 16px; }
        .result { margin: 20px 0; padding: 10px; border: 1px solid #ccc; }
        .success { background-color: #d4edda; border-color: #c3e6cb; }
        .error { background-color: #f8d7da; border-color: #f5c6cb; }
    </style>
</head>
<body>
    <h1>API连接测试</h1>
    
    <button onclick="testDirectAPI()">直接测试后端API</button>
    <button onclick="testProxyAPI()">测试代理API</button>
    <button onclick="testLogin()">测试登录</button>
    
    <div id="result"></div>

    <script>
        function showResult(message, isSuccess = true) {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = message;
            resultDiv.className = isSuccess ? 'result success' : 'result error';
        }

        async function testDirectAPI() {
            showResult('测试中...');
            try {
                const response = await fetch('http://localhost:8090/admin/login', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ adminNo: 'test', adminPassword: 'test' })
                });
                const data = await response.json();
                showResult(`直接API测试成功<br>状态: ${response.status}<br>响应: ${JSON.stringify(data)}`);
            } catch (error) {
                showResult(`直接API测试失败: ${error.message}`, false);
            }
        }

        async function testProxyAPI() {
            showResult('测试中...');
            try {
                const response = await fetch('/api/admin/login', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ adminNo: 'test', adminPassword: 'test' })
                });
                const data = await response.json();
                showResult(`代理API测试成功<br>状态: ${response.status}<br>响应: ${JSON.stringify(data)}`);
            } catch (error) {
                showResult(`代理API测试失败: ${error.message}`, false);
            }
        }

        async function testLogin() {
            showResult('测试登录中...');
            try {
                const response = await fetch('/api/admin/login', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ adminNo: 'admin', adminPassword: '123456' })
                });
                const data = await response.json();
                showResult(`登录测试完成<br>状态: ${response.status}<br>响应: ${JSON.stringify(data)}`);
            } catch (error) {
                showResult(`登录测试失败: ${error.message}`, false);
            }
        }
    </script>
</body>
</html>





